/**
 * 
 */
package com.example.ad_project;

import android.app.Activity;
import android.content.Context;
import android.graphics.Color;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AbsoluteLayout;
import android.widget.ArrayAdapter;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.nus.iss.ad.model.RetrivalListModel;

/**
 * @author Sachin
 *
 */
public class RetrivalListAdapter  extends ArrayAdapter<RetrivalListModel>  {

	private Context context;
	private RetrivalListModel[] values;
	
	public  RetrivalListAdapter(Context context, RetrivalListModel[] values) {
		   super(context, R.layout.retrival_list_row_layout, values);
		   this.context = context;
		   this.values = values;
		}
		@Override
		public View getView(int position, View convertView, ViewGroup parent) {
	        View v=convertView;
	        if (convertView == null) {
	        	LayoutInflater inflater = ((Activity)context).getLayoutInflater();
	            v = inflater.inflate(R.layout.retrival_list_row_layout, null);
	        }
	        TextView itemName = (TextView)v.findViewById(R.id.textView1);
	        TextView retrival = (TextView)v.findViewById(R.id.required);
	        TextView required = (TextView)v.findViewById(R.id.retrivable);
	        //CheckBox c1=(CheckBox)v.findViewById(R.id.checkBox1);
	//        @SuppressWarnings("deprecation")
//			AbsoluteLayout layout = (AbsoluteLayout) v.findViewById(R.layout.retrival_list_row_layout);
	        
	        RetrivalListModel rlm=values[position];
	        String itemNameString=rlm.getItemName();
	        String retrivableString=Integer.toString(rlm.getRetrivable());
	        String requiredString=Integer.toString(rlm.getRequired());
	        itemName.setText(itemNameString);
	        retrival.setText(retrivableString);
	        required.setText(requiredString);
	        
	        
	        if(rlm.isCheckFlag()){
	        	itemName.setTextColor(Color.RED); // true if sommethig wrong...
	        }else {
	        	itemName.setTextColor(Color.BLACK);
			}
	        
	        
	        //c1.setOnCheckedChangeListener((CompoundButton.OnCheckedChangeListener)context);
	       
	        return v;
			
		}
	
}
